# -*- coding: utf-8 -*-
import os
import glob, sys
import datetime as dt
import pandas as pd
import numpy as np
import xarray as xr
import FMCcalc
import time
import warnings
warnings.filterwarnings("ignore")

# Number of fire in csv
N = str(sys.argv[1])
num = int(N)

START = time.time()


####
#### Converts dew point temperature to relative humidity
####
def to_rh(T,DP):
    b = 17.67
    c = 243.5
    H = np.exp((b*(DP)/(c+(DP)))-(b*(T)/(c+(T))))
    H.values[H.values>1.]=1.
    return H


fires = pd.read_csv('../DATA/IberianPeninsula_fires_2001_2022.csv')

date=fires['Data'][num]
lon=fires['Longitude'][num]
lat=fires['Latitude'][num]

year=date.split('-')[0]
month=date.split('-')[1]
day=date.split('-')[2]
date0 = dt.datetime.strftime(dt.datetime.strptime(date, '%Y-%m-%d')-dt.timedelta(days=30), '%Y-%m-%d')
month_str = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']

Data_input = pd.DataFrame({})

# Total precipitation in m
path_era5='../DATA/ERA5/'
ds_tp0 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-{}.nc'.format(year,month)).tp.interp(latitude=lat, longitude=lon).squeeze()
if (int(month)==1):
	ds_tp1 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-12.nc'.format(str(int(year)-1))).tp.interp(latitude=lat, longitude=lon).squeeze()
	ds_tp2 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-11.nc'.format(str(int(year)-1))).tp.interp(latitude=lat, longitude=lon).squeeze()
elif (int(month)==2):
	ds_tp1 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-{}.nc'.format(year,month_str[int(month)-1])).tp.interp(latitude=lat, longitude=lon).squeeze()
	ds_tp2 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-12.nc'.format(str(int(year)-1))).tp.interp(latitude=lat, longitude=lon).squeeze()
else:
	ds_tp1 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-{}.nc'.format(year,month_str[int(month)-1])).tp.interp(latitude=lat, longitude=lon).squeeze()
	ds_tp2 = xr.open_dataset(path_era5+'TP/ERA5_total_precipitation_{}-{}.nc'.format(year,month_str[int(month)-2])).tp.interp(latitude=lat, longitude=lon).squeeze()
ds_tp = xr.concat([ds_tp2, ds_tp1, ds_tp0], "time").sel(time=slice(date0,date))
del ds_tp2, ds_tp1, ds_tp0
Data_input['time'] = ds_tp.time.data
Data_input['R'] = ds_tp.data*1000.
Data_input['R'].values[Data_input['R']<0.001] = 0.
del ds_tp

# 2m air temperature in Kelvin
ds_t20 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-{}.nc'.format(year,month)).t2m.interp(latitude=lat, longitude=lon).squeeze()
if (int(month)==1):
	ds_t21 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-12.nc'.format(str(int(year)-1))).t2m.interp(latitude=lat, longitude=lon).squeeze()
	ds_t22 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-11.nc'.format(str(int(year)-1))).t2m.interp(latitude=lat, longitude=lon).squeeze()
elif (int(month)==2):
	ds_t21 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-{}.nc'.format(year,month_str[int(month)-1])).t2m.interp(latitude=lat, longitude=lon).squeeze()
	ds_t22 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-12.nc'.format(str(int(year)-1))).t2m.interp(latitude=lat, longitude=lon).squeeze()
else:
	ds_t21 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-{}.nc'.format(year,month_str[int(month)-1])).t2m.interp(latitude=lat, longitude=lon).squeeze()
	ds_t22 = xr.open_dataset(path_era5+'T2m/ERA5_2m_temperature_{}-{}.nc'.format(year,month_str[int(month)-2])).t2m.interp(latitude=lat, longitude=lon).squeeze()
ds_t2 = xr.concat([ds_t22, ds_t21, ds_t20], "time").sel(time=slice(date0,date))
del ds_t22, ds_t21, ds_t20
Data_input['T'] = ds_t2.data-273.15
del ds_t2

# 2m dew point temperature in Kelvin
ds_dp0 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-{}.nc'.format(year,month)).d2m.interp(latitude=lat, longitude=lon).squeeze()
if (int(month)==1):
	ds_dp1 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-12.nc'.format(str(int(year)-1))).d2m.interp(latitude=lat, longitude=lon).squeeze()
	ds_dp2 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-11.nc'.format(str(int(year)-1))).d2m.interp(latitude=lat, longitude=lon).squeeze()
elif (int(month)==2):
	ds_dp1 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-{}.nc'.format(year,month_str[int(month)-1])).d2m.interp(latitude=lat, longitude=lon).squeeze()
	ds_dp2 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-12.nc'.format(str(int(year)-1))).d2m.interp(latitude=lat, longitude=lon).squeeze()
else:
	ds_dp1 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-{}.nc'.format(year,month_str[int(month)-1])).d2m.interp(latitude=lat, longitude=lon).squeeze()
	ds_dp2 = xr.open_dataset(path_era5+'Td2m/ERA5_2m_dewpoint_temperature_{}-{}.nc'.format(year,month_str[int(month)-2])).d2m.interp(latitude=lat, longitude=lon).squeeze()
ds_dp = xr.concat([ds_dp2, ds_dp1, ds_dp0], "time").sel(time=slice(date0,date))
del ds_dp2, ds_dp1, ds_dp0
Data_input['D'] = ds_dp.data-273.15
del ds_dp
Data_input['H'] = to_rh(Data_input['T'],Data_input['D'])

# Solar radiation at surface in J m-2
ds_rd0 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-{}.nc'.format(year,month)).ssrd.interp(latitude=lat, longitude=lon).squeeze()
if (int(month)==1):
	ds_rd1 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-12.nc'.format(str(int(year)-1))).ssrd.interp(latitude=lat, longitude=lon).squeeze()
	ds_rd2 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-11.nc'.format(str(int(year)-1))).ssrd.interp(latitude=lat, longitude=lon).squeeze()
elif (int(month)==2):
	ds_rd1 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-{}.nc'.format(year,month_str[int(month)-1])).ssrd.interp(latitude=lat, longitude=lon).squeeze()
	ds_rd2 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-12.nc'.format(str(int(year)-1))).ssrd.interp(latitude=lat, longitude=lon).squeeze()
else:
	ds_rd1 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-{}.nc'.format(year,month_str[int(month)-1])).ssrd.interp(latitude=lat, longitude=lon).squeeze()
	ds_rd2 = xr.open_dataset(path_era5+'Rad/ERA5_solar_radiation_{}-{}.nc'.format(year,month_str[int(month)-2])).ssrd.interp(latitude=lat, longitude=lon).squeeze()
ds_rd = xr.concat([ds_rd2, ds_rd1, ds_rd0], "time").sel(time=slice(date0,date))
del ds_rd2, ds_rd1, ds_rd0
Data_input['S'] = ds_rd.data/3600.
Data_input['S'].values[Data_input['S']<0.001] = 0.
del ds_rd

path_cmip6='../DATA/CMIP6/'
models=['EC-Earth3', 'CESM2-WACCM', 'MPI-ESM1-2-HR', 'MRI-ESM2-0', 'NorESM2-MM']
experiments=['piControl', 'ssp245']
for model in models:
	for experiment in experiments:
		Data_input_daily = pd.DataFrame({})
		# 2m air temperature in Kelvin
		ds_t20 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month)).tas.interp(latitude=lat, longitude=lon).squeeze()
		if (int(month)==1):
			ds_t21 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-12.nc'.format(str(int(year)-1))).tas.interp(latitude=lat, longitude=lon).squeeze()
			ds_t22 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-11.nc'.format(str(int(year)-1))).tas.interp(latitude=lat, longitude=lon).squeeze()
		elif (int(month)==2):
			ds_t21 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month_str[int(month)-1])).tas.interp(latitude=lat, longitude=lon).squeeze()
			ds_t22 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-12.nc'.format(str(int(year)-1))).tas.interp(latitude=lat, longitude=lon).squeeze()
		else:
			ds_t21 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month_str[int(month)-1])).tas.interp(latitude=lat, longitude=lon).squeeze()
			ds_t22 = xr.open_dataset(path_cmip6+model+'/tas/Anom_'+experiment+'/ERA5_tas_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month_str[int(month)-2])).tas.interp(latitude=lat, longitude=lon).squeeze()
		ds_t2 = xr.concat([ds_t22, ds_t21, ds_t20], "time").sel(time=slice(date0,date))
		del ds_t22, ds_t21, ds_t20
		Data_input_daily['time'] = ds_t2.time.data
		Data_input_daily['time'].iloc[0] = Data_input_daily['time'].iloc[0]-dt.timedelta(hours=12)
		Data_input_daily['time'].iloc[-1] = Data_input_daily['time'].iloc[-1]+dt.timedelta(hours=11)
		Data_input_daily['T'] = ds_t2.data
		Data_input['T_'+experiment+'_'+model] = Data_input['T']+Data_input_daily.set_index("time").resample("H").ffill().reset_index()['T'].values
		del ds_t2

		# 2m dew point temperature in Kelvin
		ds_dp0 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month)).tas.interp(latitude=lat, longitude=lon).squeeze()
		if (int(month)==1):
			ds_dp1 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-12.nc'.format(str(int(year)-1))).tas.interp(latitude=lat, longitude=lon).squeeze()
			ds_dp2 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-11.nc'.format(str(int(year)-1))).tas.interp(latitude=lat, longitude=lon).squeeze()
		elif (int(month)==2):
			ds_dp1 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month_str[int(month)-1])).tas.interp(latitude=lat, longitude=lon).squeeze()
			ds_dp2 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-12.nc'.format(str(int(year)-1))).tas.interp(latitude=lat, longitude=lon).squeeze()
		else:
			ds_dp1 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month_str[int(month)-1])).tas.interp(latitude=lat, longitude=lon).squeeze()
			ds_dp2 = xr.open_dataset(path_cmip6+model+'/tdps/Anom_'+experiment+'/ERA5_tdps_'+model+'_'+experiment+'_{}-{}.nc'.format(year,month_str[int(month)-2])).tas.interp(latitude=lat, longitude=lon).squeeze()
		ds_dp = xr.concat([ds_dp2, ds_dp1, ds_dp0], "time").sel(time=slice(date0,date))
		del ds_dp2, ds_dp1, ds_dp0
		Data_input_daily['D'] = ds_dp.data
		Data_input['D_'+experiment+'_'+model] = Data_input['D']+Data_input_daily.set_index("time").resample("H").ffill().reset_index()['D'].values
		del ds_dp
		Data_input['H_'+experiment+'_'+model] = to_rh(Data_input['T_'+experiment+'_'+model],Data_input['D_'+experiment+'_'+model])
		Data_input = Data_input.drop(columns=['D_'+experiment+'_'+model])


FMC_1h=pd.DataFrame({})
FMC_10h=pd.DataFrame({})
FMC_100h=pd.DataFrame({})
FMC_1h['time'] = Data_input['time']
FMC_10h['time'] = Data_input['time']
FMC_100h['time'] = Data_input['time']
FMC_1h = FMC_1h.assign(FMC=0.)
FMC_1h = FMC_1h.assign(FMC_min=0.)
FMC_1h = FMC_1h.assign(FMC_max=0.)
FMC_10h = FMC_10h.assign(FMC=0.)
FMC_10h = FMC_10h.assign(FMC_min=0.)
FMC_10h = FMC_10h.assign(FMC_max=0.)
FMC_100h = FMC_100h.assign(FMC=0.)
FMC_100h = FMC_100h.assign(FMC_min=0.)
FMC_100h = FMC_100h.assign(FMC_max=0.)
for model in models:
	for experiment in experiments:
		name='FMC_'+experiment+'_'+model
		FMC_1h[name] = FMC_1h['FMC'].copy()
		FMC_10h[name] = FMC_10h['FMC'].copy()
		FMC_100h[name] = FMC_100h['FMC'].copy()

stick1h = FMCcalc.create_stick1h()
stick10h = FMCcalc.create_stick10h()
stick100h = FMCcalc.create_stick100h()
FMCcalc.initialize(stick1h,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*stick1h["wmx"])
FMCcalc.initialize(stick10h,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*stick10h["wmx"])
FMCcalc.initialize(stick100h,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*stick100h["wmx"])

stick1h_min = FMCcalc.create_stick1h()
stick10h_min = FMCcalc.create_stick10h()
stick100h_min = FMCcalc.create_stick100h()
FMCcalc.initialize(stick1h_min,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.1*stick1h_min["wmx"])
FMCcalc.initialize(stick10h_min,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.1*stick10h_min["wmx"])
FMCcalc.initialize(stick100h_min,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.1*stick100h_min["wmx"])

stick1h_max = FMCcalc.create_stick1h()
stick10h_max = FMCcalc.create_stick10h()
stick100h_max = FMCcalc.create_stick100h()
FMCcalc.initialize(stick1h_max,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.9*stick1h_max["wmx"])
FMCcalc.initialize(stick10h_max,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.9*stick10h_max["wmx"])
FMCcalc.initialize(stick100h_max,Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.9*stick100h_max["wmx"])

sticks1h_piControl = {model:FMCcalc.create_stick1h() for model in models}
sticks10h_piControl = {model:FMCcalc.create_stick10h() for model in models}
sticks100h_piControl = {model:FMCcalc.create_stick100h() for model in models}
sticks1h_ssp245 = {model:FMCcalc.create_stick1h() for model in models}
sticks10h_ssp245 = {model:FMCcalc.create_stick10h() for model in models}
sticks100h_ssp245 = {model:FMCcalc.create_stick100h() for model in models}

for model in models:
	FMCcalc.initialize(sticks1h_piControl[model],Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*sticks1h_piControl[model]["wmx"])
	FMCcalc.initialize(sticks10h_piControl[model],Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*sticks10h_piControl[model]["wmx"])
	FMCcalc.initialize(sticks100h_piControl[model],Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*sticks100h_piControl[model]["wmx"])
	FMCcalc.initialize(sticks1h_ssp245[model],Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*sticks1h_ssp245[model]["wmx"])
	FMCcalc.initialize(sticks10h_ssp245[model],Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*sticks10h_ssp245[model]["wmx"])
	FMCcalc.initialize(sticks100h_ssp245[model],Data_input['T'][0],Data_input['H'][0],Data_input['S'][0],Data_input['T'][0],Data_input['H'][0],0.5*sticks100h_ssp245[model]["wmx"])

for t in range(1,FMC_1h.index.size):

	stick1h = FMCcalc.main(stick1h, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick10h = FMCcalc.main(stick10h, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick100h = FMCcalc.main(stick100h, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick1h_min = FMCcalc.main(stick1h_min, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick10h_min = FMCcalc.main(stick10h_min, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick100h_min = FMCcalc.main(stick100h_min, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick1h_max = FMCcalc.main(stick1h_max, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick10h_max = FMCcalc.main(stick10h_max, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	stick100h_max = FMCcalc.main(stick100h_max, 1., Data_input['T'][t],Data_input['H'][t],Data_input['S'][t],Data_input['R'][t])
	
	FMC_1h['FMC'].values[t] = FMCcalc.stick_meanW_weight(stick1h)
	FMC_10h['FMC'].values[t] = FMCcalc.stick_meanW_weight(stick10h)
	FMC_100h['FMC'].values[t] = FMCcalc.stick_meanW_weight(stick100h)
	FMC_1h['FMC_min'].values[t] = FMCcalc.stick_meanW_weight(stick1h_min)
	FMC_10h['FMC_min'].values[t] = FMCcalc.stick_meanW_weight(stick10h_min)
	FMC_100h['FMC_min'].values[t] = FMCcalc.stick_meanW_weight(stick100h_min)
	FMC_1h['FMC_max'].values[t] = FMCcalc.stick_meanW_weight(stick1h_max)
	FMC_10h['FMC_max'].values[t] = FMCcalc.stick_meanW_weight(stick10h_max)
	FMC_100h['FMC_max'].values[t] = FMCcalc.stick_meanW_weight(stick100h_max)

	for model in models:
		sticks1h_piControl[model] = FMCcalc.main(sticks1h_piControl[model], 1., Data_input['T_piControl_'+model][t],Data_input['H_piControl_'+model][t],Data_input['S'][t],Data_input['R'][t])
		sticks10h_piControl[model] = FMCcalc.main(sticks10h_piControl[model], 1., Data_input['T_piControl_'+model][t],Data_input['H_piControl_'+model][t],Data_input['S'][t],Data_input['R'][t])
		sticks100h_piControl[model] = FMCcalc.main(sticks100h_piControl[model], 1., Data_input['T_piControl_'+model][t],Data_input['H_piControl_'+model][t],Data_input['S'][t],Data_input['R'][t])
		sticks1h_ssp245[model] = FMCcalc.main(sticks1h_ssp245[model], 1., Data_input['T_ssp245_'+model][t],Data_input['H_ssp245_'+model][t],Data_input['S'][t],Data_input['R'][t])
		sticks10h_ssp245[model] = FMCcalc.main(sticks10h_ssp245[model], 1., Data_input['T_ssp245_'+model][t],Data_input['H_ssp245_'+model][t],Data_input['S'][t],Data_input['R'][t])
		sticks100h_ssp245[model] = FMCcalc.main(sticks100h_ssp245[model], 1., Data_input['T_ssp245_'+model][t],Data_input['H_ssp245_'+model][t],Data_input['S'][t],Data_input['R'][t])
		
		FMC_1h['FMC_piControl_'+model].values[t] = FMCcalc.stick_meanW_weight(sticks1h_piControl[model])
		FMC_10h['FMC_piControl_'+model].values[t] = FMCcalc.stick_meanW_weight(sticks10h_piControl[model])
		FMC_100h['FMC_piControl_'+model].values[t] = FMCcalc.stick_meanW_weight(sticks100h_piControl[model])
		FMC_1h['FMC_ssp245_'+model].values[t] = FMCcalc.stick_meanW_weight(sticks1h_ssp245[model])
		FMC_10h['FMC_ssp245_'+model].values[t] = FMCcalc.stick_meanW_weight(sticks10h_ssp245[model])
		FMC_100h['FMC_ssp245_'+model].values[t] = FMCcalc.stick_meanW_weight(sticks100h_ssp245[model])


for column in FMC_1h.columns:
	if column!='time':
		FMC_1h[column] = FMC_1h[column].astype('float32').map('{:.5f}'.format)
		FMC_10h[column] = FMC_10h[column].astype('float32').map('{:.5f}'.format)
		FMC_100h[column] = FMC_100h[column].astype('float32').map('{:.5f}'.format)

FMC_1h.to_csv('../OUTS/FMC_Nelson_csv/N'+N+'_fmc1h.csv')
FMC_10h.to_csv('../OUTS/FMC_Nelson_csv/N'+N+'_fmc10h.csv')
FMC_100h.to_csv('../OUTS/FMC_Nelson_csv/N'+N+'_fmc100h.csv')

END = time.time()
tempo = END-START
print(str(FMC_1h['time'][t])+', Tempo: {:.0}s'.format(tempo))
